/* 
 * File:   BlockRenderer.cpp
 * Author: Nick
 * 
 * Created on 20 April 2011, 11:10 PM
 */

#include "BlockRenderer.h"

class Block;

BlockRenderer::BlockRenderer() {

}

BlockRenderer::~BlockRenderer() {
}

NullRenderer::NullRenderer(){

}
NullRenderer::~NullRenderer(){

}

void NullRenderer::draw(Block* block){
    
}


CubeRenderer::CubeRenderer() {
    _rl_cube = 0;
}

CubeRenderer::~CubeRenderer() {
}

void CubeRenderer::draw(Block* block) {
    init();
    glCallList(_rl_cube);
}

void CubeRenderer::init() {

    
    if (_rl_cube == 0) {
    static const int cube_faces = 6;
    static const GLfloat cube_vertices[8][3] = { {0.0, 0.0, 1.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {0.0, 1.0, 1.0}, {0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 0.0}, {0.0, 1.0, 0.0} };
    static const GLfloat cube_normals[6][3] = { {0.0, 0.0, +1.0}, {0.0, 0.0, -1.0}, {+1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0}, {0.0, +1.0, 0.0}, {0.0, -1.0, 0.0} };
    static const int     cube_indices[6][4] = { {0, 1, 2, 3}, {5, 4, 7, 6}, {1, 5, 6, 2}, {4, 0, 3, 7}, {3, 2, 6, 7}, {1, 0, 4, 5} };

    _rl_cube = glGenLists(1);
        glNewList(_rl_cube, GL_COMPILE);

        glColor3f(1,1,1);
        for (int i = 0; i < cube_faces; i++) {
            glBegin(GL_QUADS);
            glNormal3fv(cube_normals[i]);

            for (int j = 0; j < 4; j++) {
                glVertex3fv(cube_vertices[cube_indices[i][j]]);
            }
            glEnd();
        }

        glColor3f(1,0,0);
        for (int i = 0; i < cube_faces; i++) {
            glBegin(GL_LINE_LOOP);
            for (int j = 0; j < 4; j++) {
                glVertex3fv(cube_vertices[cube_indices[i][j]]);
            }
            glEnd();
        }
        
        

        glEndList();
    }
}